﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace FCMS.Mail.Configuration
{
    internal class EmailSection : ConfigurationSection
    {
        private static EmailSection s_instance;

        internal static EmailSection Instance
        {
            get
            {
                if (s_instance == null)
                {
                    lock (typeof(EmailSection))
                    {
                        if (s_instance == null)
                        {
                            s_instance = (EmailSection)ConfigurationManager.GetSection("EmailSection");
                        }
                    }
                }
                return s_instance;
            }
        }

        [ConfigurationProperty("sendAsync", IsRequired = false, DefaultValue = false)]
        public bool SendAsync
        {
            get
            {
                return (bool)this["sendAsync"];
            }
        }

        [ConfigurationProperty("host", IsRequired = true)]
        public string Host
        {
            get
            {
                return (string)this["host"];
            }
        }

        [ConfigurationProperty("port", IsRequired = false, DefaultValue = 25)]
        public int Port
        {
            get
            {
                return (int)this["port"];
            }
        }

        [ConfigurationProperty("timeout", IsRequired = false, DefaultValue = 10)]
        public int Timeout
        {
            get
            {
                return (int)this["timeout"];
            }
        }

        [ConfigurationProperty("from", IsRequired = true)]
        public string From
        {
            get
            {
                return (string)this["from"];
            }
        }

        [ConfigurationProperty("displayName", IsRequired = false)]
        public string DisplayName
        {
            get
            {
                return (string)this["displayName"];
            }
        }

        [ConfigurationProperty("credential", IsRequired = false)]
        public SmtpCredentialElement Credential
        {
            get
            {
                return (SmtpCredentialElement)this["credential"];
            }
        }
    }
}
